import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {//默认去主界面
        path: '/',redirect:'/manager/home'
    },
    {//登录界面
      path: '/login',component:() => import('../views/Login.vue'),
    },
    {//注册界面
      path: '/register',component:() => import('../views/Register.vue'),
    },
    {//前台主界面路径
      path: '/front', meta: {name: '前台主页'},component:() => import('../views/Front.vue'),
      children: [
        {//子路径，首页
          path: 'fronthome', meta: {name: '前台首页'},
          component: () => import('../views/FrontHome.vue')},
        {//子路径，个人信息
          path: 'person', meta: {name: '个人信息'},
          component: () => import('../views/Person.vue')},
        {//子路径，查看他人信息
          path: 'otherperson/:userId', meta: {name: '他人信息'},
          component: () => import('../views/OtherPerson.vue'),
          props: true},
        {//子路径，贴子详情
          path: 'forumdetail', meta: {name: '贴子详情'},
          component: () => import('../views/ForumDetail.vue')},
        {//子路径，论坛信息
          path: 'frontforum', meta: {name: '论坛信息'},
          component: () => import('../views/FrontForum.vue')},
        {//子路径，我的贴子
          path: 'ownwritten', meta: {name: '我的贴子'},
          component: () => import('../views/OwnWritten.vue')},
        {//子路径，我的评论
          path: 'frontcomment', meta: {name: '我的评论'},
          component: () => import('../views/FrontComment.vue')},
      ]
    },
    /*{//加载评论信息（路由跳转 废案）
      path: '/front/forumdetail', name: 'ForumDetail', component: () => import('../views/ForumDetail.vue'), props: true, // 启用props接收参数[3,4](@ref)
      children: [
        {
          path: 'comment', name: 'CommentDetail', component: () => import('../views/CommentDetail.vue'),
          // 可添加props配置接收父路由参数
          props: (route) => ({
            writtenId: route.query.id
          })
        }
      ]
    },*/
    {//后台主界面路径
      path: '/manager', meta: {name: '主页'},
      component: () => import('../views/Manager.vue'),
      children: [ // 统一使用 children 字段
        {//子路径，首页
          path: 'home', meta: {name: '首页'},
          component: () => import('../views/Home.vue')
        },
        {//子路径，管理界面
          path: 'admin', meta: {name: '管理员信息'},
          component: () => import('../views/Admin.vue') // 箭头函数导入
        },
        {//子路径，用户界面
          path: 'user', meta: {name: '用户信息'},
          component: () => import('../views/User.vue')
        },
        {//子路径，个人信息
          path: 'person', meta: {name: '个人信息'},
          component: () => import('../views/Person.vue')
        },
        {//子路径，修改密码
          path: 'updatepassword', meta: {name: '修改密码'},
          component: () => import('../views/UpdatePassword.vue')
        },
        {//子路径，系统公告
          path: 'notice', meta: {name: '系统公告'},
          component: () => import('../views/Notice.vue')
        },
        {//子路径，发贴空间
          path: 'written', meta: {name: '发贴空间'},
          component: () => import('../views/Written.vue')
        },
        {//子路径，贴子分类
          path: 'category', meta: {name: '贴子分类'},
          component: () => import('../views/Category.vue')
        },
        {//子路径，审核信息
          path: 'apply', meta: {name: '审核信息'},
          component: () => import('../views/Apply.vue')
        },
        {//子路径，论坛信息
          path: 'forum', meta: {name: '论坛信息'},
          component: () => import('../views/Forum.vue')
        },
        {//子路径，评论信息
          path: 'comment', meta: {name: '评论信息'},
          component: () => import('../views/Comment.vue')
        },
        {//子路径，查看他人信息
          path: 'otherperson/:userId', meta: {name: '他人信息'},
          component: () => import('../views/OtherPerson.vue'),
          props: true
        },
        {//子路径，评论信息
          path: 'comment/:writtenId', meta: {name: '评论信息'},
          component: () => import('../views/Comment.vue'),
          props: true
        },
      ]
    },
    {//404notfound界面
      path: '/notFound',
      component: () => import('../views/404.vue')
    },
    {//未找到界面，报404错误，跳转notfound界面
      path: '/:pathMatch(.*)',
      redirect: '/notFound'
    }
  ],
})

export default router